import 'package:flutter/material.dart';
import 'package:mall/utils/refresh/warp_refresh_controller.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

class RefreshComponent extends StatelessWidget {
  const RefreshComponent({
    super.key,
    required this.controller,
    required this.child,
    this.onRefresh,
    this.onLoading,
  });

  final WarpRefreshController controller;

  final Widget child;

  final VoidCallback? onRefresh;

  final VoidCallback? onLoading;

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
      controller: controller,
      header: classicHeader(),
      footer: classicFooter(),
      enablePullUp: onLoading != null,
      enablePullDown: onRefresh != null,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: child,
    );
  }

    /// Header
  Widget classicHeader() {
    return const ClassicHeader(
      idleText: '下拉刷新',
      releaseText: "松开开始刷新数据",
      completeText: '刷新完成',
      refreshingText: '刷新中...',
    );
  }

  Widget classicFooter() {
    return const ClassicFooter(
      idleText: '上拉加载',
      loadingText: '加载中...',
      canLoadingText: '松开开始加载数据',
      noDataText: '暂无更多数据',
    );
  }
}
